package com.zc.controller;

import com.zc.entity.User;
import com.zc.mapper.BugMapper;
import com.zc.mapper.ItemMapper;
import com.zc.mapper.NeedsMapper;
import com.zc.mapper.UserMapper;
import com.zc.util.DataUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.*;

@Controller
public class SessionController {
    @Autowired
    UserMapper userMapper;
    @Autowired
    BugMapper bugMapper;
    @Autowired
    ItemMapper itemMapper;
    @Autowired
    NeedsMapper needsMapper;
    Logger logger = LoggerFactory.getLogger(getClass());
    @ResponseBody
    @GetMapping("/getuserlist")
    public Map getuserlist(HttpSession session)
    {
        Map map=new HashMap();
        List list=userMapper.selectAll();
        for (int i=0;i<list.size();i++)
        {
            User user=(User) list.get(i);
            map.put(user.getId(),user.getRealname());
        }
        int userid=(int)session.getAttribute("userid");
        map.put("userid",userid);
        User user = userMapper.selectByPrimaryKey(userid);
        map.put("usergrade",user.getGrade());
        return map;
    }
    @ResponseBody
    @GetMapping("getdata")
    public  List getdata(HttpSession session)
    {
        List list=new ArrayList();
       int a= bugMapper.selectByDate(DataUtils.getDate());
       list.add(a);
       int b= needsMapper.selectByDate(DataUtils.getDate());
       list.add(b);
        List list1=new ArrayList();
        list1.add(needsMapper.selectCountStatus());
        list1.add(bugMapper.selectCountStatus());
        list1.add(bugMapper.selectCountStatuss()+needsMapper.selectCountStatuss());
        list.add(list1);
       logger.info(list.toString());
        return list;
    }
}
